👋 Welcome!
In this workshop, we will explore the advanced use of containers on HPC resources, like UCLA’s Hoffman2. This is a follow-up to a previous workshop “Containers for HPC Resources”
🚀 Dive into advanced container topics
🧰 Build containers tailored for HPC resources
💡 Got suggestions for upcoming workshops?
cpeterson@oarc.ucla.edu
👀 Viewing the slides
https://github.com/ucla-oarc-hpc/WS_MakingContainers
Find this slide deck in the slides
folder.
WS_MakingContainers.qmd
Note
This presentation was created with Quarto and RStudio.
WS_MakingContainers.qmd
In this workshop, we will engage in hands-on exercises.
Requirements:
sudo
permissions)Alternative: Virtual Machine
Pre-configured Virtual Machine (VM) available on BOX
wscontainer.ova
Apptainer
Docker
Podman
🏭 Build a container by installing Apptainer on your computer (where you have root/sudo access) to create a container
📥 Use a pre-built container
🗄️ A SIF file contains the image for the container
📁 A sandbox container is a directory format used for writable containers
🤖 Interactive (qrsh) session
📄 Batch (qsub) job
On Hoffman2, to use apptainer, all you need to do is load the module
module load intel/2022.1.1
This example uses PyTorch 🧠
Similar to last week’s example
EX1
directory
pytorch.py
fileNext, we will start a WRITABLE interactive shell session in the sandbox image:
--writable
will allow us to modify the containerFrom here, we can run any commands we need to install PyTorch:
apt update
apt install -y python3 python3-pip
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
exit
Convert the sandbox container to a SIF file, pytorch.sif
Run our SIF container:
We do not need to be root since we are just running python3.
Transfer our container:
Example job script to run on Hoffman2:
In this example, we used an interactive approach to install a python package in a container.
This is a useful way to experiment installing of your applications
I coded a chemistry app located on github.
To install, we need
Instead of installing these dependencies on H2 (or loding modules)
Lets build a container!!
We will build this container by:
Definition Files are like the blueprint to building a custom container.
Instead of interactively modifying a sandbox image, we can build a container with this Definition file
The quill.def
file has all steps needed to build the QUILL container.
Bootstrap: docker
From: ubuntu:20.04
%labels
Author Charles Peterson <cpeterson@oarc.ucla.edu>
%post
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git python3 python3-dev python3-pip \
libeigen3-dev ca-certificates cmake make gcc g++
rm -rf /var/lib/apt/lists/*
pip3 install pyscf
ln -s /usr/bin/python3 /usr/bin/python
mkdir -pv /apps
cd /apps
git clone https://github.com/charliecpeterson/QUILL
cd QUILL
mkdir build ; cd build
cmake ..
make
%environment
export PATH=/apps/QUILL/build:$PATH
Sections:
%labels
- adds metadata%post
- This section runs commands to setup the final container%environment
- define environment variables inside containerDockerfile-quill
file is used by Docker to create containerFROM ubuntu:20.04
## Author Charles Peterson <cpeterson@arc.ucla.edu>
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git python3 python3-dev python3-pip \
libeigen3-dev ca-certificates cmake make gcc g++ \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install pyscf ; ln -s /usr/bin/python3 /usr/bin/python
RUN mkdir -pv /apps \
&& cd /apps \
&& git clone https://github.com/charliecpeterson/QUILL \
&& cd QUILL \
&& mkdir build ; cd build \
&& cmake .. ; make
ENV PATH=/apps/QUILL/build:$PATH
In the previous slides, we created a SIF file (quill.sif), then transfer (scp) them to Hoffman2.
Instead of this, we can upload our container to a Container Registry.
Lets create a repo on DockerHub
charliecpeterson
docker.io
ghcr.io
Push our final container to GitHub
podman tag quill:1.0 ghcr.io/charliecpeterson/quill:1.0
podman push ghcr.io/charliecpeterson/quill:1.0
Then pull the container on Hoffman2
DockerHub and GitHub Packages are popular cloud registries. You can create and deploy a local container registry.
Once the container is on Hoffman2, submit job.
#!/bin/bash
#$ -cwd
#$ -o quill.$JOB_ID
#$ -j y
#$ -l h_rt=1:00:00,h_data=15G
#$ -pe shared 1
#$ -l arch=intel-gold*
# load the job environment:
. /u/local/Modules/default/init/modules.sh
module load apptainer
# Container part: apptainer exec QUILL.sif
# Command: QUILL.x /apps/QUILL/input.inp
time apptainer exec quill.sif QUILL.x test.inp
Submit job script
More information on using Definition files
More information on using Dockerfiles
Anaconda is a very popular python and R distributaion for simplifying package installation
Though Anaconda can be tricky installing in a container due to environment setup.
We will have an example using Anaconda to install an application in a container.
We will go over creating a definition file for a example with Anaconda.
We will install the software h2o.ai. This is a great machine learning platform that has Python and R libraries.
In this example, we will use Anaconda to install h2o packages inside python and R.
The h2o.def
file
%runscript
to setup Anaconda env for apptainer run
$@
take arguments as a string from the command lineapptainer run h2o.sif "python h2o-test.py"
Bootstrap: docker
From: ubuntu:22.04
%labels
Author Charles Peterson <cpeterson@oarc.ucla.edu>
%post
export DEBIAN_FRONTEND=noninteractive
apt -y update ; apt -y upgrade
apt install -y wget libbz2-dev wget git gcc libreadline-dev zlib1g-dev default-jre default-jdk
#Install anaconda
cd /tmp
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
bash Anaconda3-2022.05-Linux-x86_64.sh -b -p /opt/anaconda
bash -c "source /opt/anaconda/etc/profile.d/conda.sh
conda create -n h2oai h2o -c h2oai -c conda-forge
"
%runscript
exec bash -c "source /opt/anaconda/etc/profile.d/conda.sh
conda activate h2oai
$@"
Note
apptainer exec foo.sif [COMMAND]
apptainer run foo.sif
jupyter.def
# get an interactive job
qrsh -l h_data=10G
# Create tmp directories
mkdir -pv $SCRATCH/rstudiotmp/var/lib
mkdir -pv $SCRATCH/rstudiotmp/var/run
mkdir -pv $SCRATCH/rstudiotmp/tmp
#Setup apptainer
module load apptainer
#Run rstudio
apptainer run -B $SCRATCH/rstudiotmp/var/lib:/var/lib/rstudio-server -B $SCRATCH/rstudiotmp/var/run:/var/run/rstudio-server -B $SCRATCH/rstudiotmp/tmp:/tmp rstudio.sif
# This command will display some information and a `ssh -L ...` command for you to run on a separate terminal
Size of container
Multi-Stage
approachQuestions? Comments? 🤔
Charles Peterson cpeterson@oarc.ucla.edu